//
//  UseCarDiao.m
//  xjairOA
//
//  Created by apple on 16-2-2.
//  Copyright (c) 2016年 net. All rights reserved.
//

#import "UseCarDiao.h"
#import "Constants.h"

@implementation UseCarDiao
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.picker.delegate = self;
    self.picker.dataSource = self;
    self.appDelegate = [UIApplication sharedApplication].delegate;
    NSDictionary * params = @{@"model":@"useCarDiao"};
    self.dataArray = [[NSMutableArray alloc] init];
    [self.appDelegate.manager
     GET:UserCarMutiAction
     parameters:params
     success:^(AFHTTPRequestOperation *operation, id responseObject) {
         self.data = responseObject;
         for (NSDictionary * dict in self.data){
             //NSLog(@"%@",[dict objectForKey:@"userName"]);
             [self.dataArray addObject:[dict objectForKey:@"userName"]];
         }
         [self.picker reloadAllComponents];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         UIAlertView * alert = [[UIAlertView alloc]
                                initWithTitle:@"提示"
                                message:@"获取服务器响应出错！"
                                delegate:nil
                                cancelButtonTitle:@"确定"
                                otherButtonTitles:nil];
         [alert show];
     }];
    UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonSystemItemCancel target:self action:@selector(finish)];
    [self.navigationItem setRightBarButtonItem:rightButton];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return self.dataArray.count;
}

- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [self.dataArray objectAtIndex:row];
}


- (void)finish
{
    NSInteger row = [self.picker selectedRowInComponent:0];
    //    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"你选中的是:%@",[number objectAtIndex:row]] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
    //    [alert show];
    UILabel * label9 = (UILabel*)[((UIViewController*)[self.navigationController.viewControllers objectAtIndex:2]).view viewWithTag:9];
    label9.text = [self.dataArray objectAtIndex:row];
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
}

@end
